﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace projectOklahoma
{
    public partial class workingForm : Form
    {
        int connectionNum;
        int activeQueryNum;

        public workingForm(int connum)
        {
            InitializeComponent();
            connectionNum = connum;
            activeQueryNum = -1;
        }

        private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F9)
            {
                // execute current lines' query

                string ec = "";
                string query = richTextBox1.Text;

                if (OracleConnectionManager.executeQuery(query, connectionNum, ref ec, queryDatagrid, ref activeQueryNum) != 0)
                {
                    System.Windows.Forms.MessageBox.Show(ec);
                }
            }
        }

        private void queryDatagrid_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        {
            object o = new object();
            OracleConnectionManager.getQueryData(e.RowIndex, e.ColumnIndex, ref o, queryDatagrid,activeQueryNum);
            e.Value = o;
        }

        private void queryDatagrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Down)
            {
                int grpos = queryDatagrid.CurrentCell.RowIndex;
                if (grpos == (queryDatagrid.RowCount - 1))
                {
                    if (!OracleConnectionManager.isFetchComplete(activeQueryNum))
                    {
                        queryDatagrid.RowCount += 1;
                    }
                }
            }
        }
    }
}
